home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / cucd / programming / oberonv4 / source / system / direlems.mod (.txt) < prev    next >
Oberon Text  |  1996-06-02  |  4KB  |  106 lines

  1. Syntax10.Scn.Fnt
  2. StampElems
  3. Alloc
  4. 2 Jun 96
  5. Syntax10b.Scn.Fnt
  6. FoldElems
  7. MODULE DirElems;    (** HM 
  8.  (mah auto-update)*)
  9. IMPORT Out, Viewers, Texts, TextFrames, Oberon, PopupElems, Directories, Display;
  10.     Elem* = POINTER TO ElemDesc;
  11.     ElemDesc* = RECORD (PopupElems.ElemDesc)
  12.     END ;
  13.     NotifyMsg = RECORD(Display.FrameMsg) END ;
  14.     Frame = POINTER TO RECORD(Display.FrameDesc) elem: Elem END ;
  15.     oldDirNotify: Directories.Notifier;
  16.     curDirName: ARRAY 32 OF CHAR;
  17. PROCEDURE ReadName (t: Texts.Text; pos: LONGINT; VAR name: ARRAY OF CHAR);
  18.     VAR r: Texts.Reader; ch, stopch: CHAR; i: INTEGER; beg, end, time: LONGINT;
  19. BEGIN
  20.     Texts.OpenReader(r, t, pos); Texts.Read(r, ch); i := 0;
  21.     IF ch = '"' THEN Texts.Read(r, ch);
  22.         WHILE ~r.eot & (ch # '"') DO name[i] := ch; INC(i); Texts.Read(r, ch) END
  23.     ELSE
  24.         WHILE ~r.eot & (ch > " ") DO name[i] := ch; INC(i); Texts.Read(r, ch) END
  25.     END ;
  26.     name[i] := 0X;
  27.     IF name = "^" THEN
  28.         Oberon.GetSelection(t, beg, end, time);
  29.         IF time >= 0 THEN ReadName(t, beg, name) END
  30. END ReadName;
  31. PROCEDURE SetDirName;
  32.     VAR i, j: INTEGER; name: ARRAY 256 OF CHAR; d, d0: Directories.Directory;
  33. BEGIN
  34.     d := Directories.Current(); d0 := Directories.Startup();
  35.     Out.String("d  : "); IF d#NIL THEN Out.String(d.path) ELSE Out.String("NIL!") END; Out.Ln;
  36.     Out.String("d0: "); IF d0#NIL THEN Out.String(d0.path) ELSE Out.String("NIL!") END; Out.Ln;
  37.     i := 0; WHILE (d0.path[i] # 0X) & (CAP(d0.path[i]) = CAP(d.path[i])) DO INC(i) END ;
  38.     IF (d0.path[i] = 0X) & ((d.path[i] = 0X) OR (d.path[i] = Directories.delimiter)) THEN
  39.         IF d.path[i] = Directories.delimiter THEN
  40.             name[0] := "$"; INC(i);
  41.             j := 0; REPEAT INC(j); name[j] := d.path[i]; INC(i) UNTIL name[j] = 0X
  42.         ELSE 
  43.             name := "$";
  44.         END
  45.     ELSE
  46.         COPY(d.path, name)
  47.     END ;
  48.     i := 0; WHILE name[i] # 0X DO INC(i) END ;
  49.     IF i < 32 THEN COPY(name, curDirName)
  50.     ELSE curDirName[31] := 0X; j := 31;
  51.         REPEAT DEC(i); DEC(j); curDirName[j] := name[i] UNTIL j = 1;
  52.         curDirName[0] := "*"
  53. END SetDirName;
  54. PROCEDURE Exec (e: Elem; pos: LONGINT);
  55.     VAR msg: NotifyMsg; name: ARRAY 256 OF CHAR;
  56. BEGIN ReadName(e.menu, pos, name); Directories.Change(name)
  57. END Exec;
  58. PROCEDURE DirNotify (op: INTEGER; path, name: ARRAY OF CHAR);
  59. VAR msg: NotifyMsg;
  60. BEGIN
  61.     IF op = Directories.change THEN SetDirName; Viewers.Broadcast (msg) END ;
  62.     oldDirNotify (op, path, name)
  63. END DirNotify;
  64. PROCEDURE HandleFrame(f: Display.Frame; VAR msg: Display.FrameMsg);
  65.     VAR m: TextFrames.UpdateMsg;
  66. BEGIN
  67.     IF msg IS NotifyMsg THEN
  68.         WITH f: Frame DO
  69.             TextFrames.NotifyDisplay (Texts.ElemBase(f.elem), TextFrames.replace, Texts.ElemPos(f.elem), Texts.ElemPos(f.elem)+1)
  70.         END
  71. END HandleFrame;
  72. PROCEDURE Handle* (e: Texts.Elem; VAR m: Texts.ElemMsg);
  73.     VAR e1: Elem; f: Frame;
  74. BEGIN
  75.     WITH e: Elem DO
  76.         COPY (curDirName, e.name);
  77.         WITH m: Texts.CopyMsg DO NEW(e1); m.e := e1; PopupElems.Handle(e, m)
  78.         |  m: Texts.IdentifyMsg DO m.mod := "DirElems"; m.proc := "Alloc"
  79.         |  m: PopupElems.ExecMsg DO Exec(e, m.pos)
  80.         |  m: TextFrames.DisplayMsg DO
  81.             IF ~m.prepare THEN
  82.                 NEW (f); f.X := m.X0; f.Y := m.Y0; f.W := 1; f.H := 1;    (* trick (c) mah/cs *)
  83.                 f.handle := HandleFrame; f.elem := e;
  84.                 m.elemFrame := f
  85.             END ;
  86.             PopupElems.Handle (e, m)
  87.         ELSE PopupElems.Handle(e, m)
  88.         END
  89. END Handle;
  90. PROCEDURE Alloc*;
  91.     VAR e: Elem;
  92. BEGIN
  93.     NEW(e); e.handle := Handle; Texts.new := e
  94. END Alloc;
  95. PROCEDURE Insert*;
  96.     VAR e: Elem; insert: TextFrames.InsertElemMsg;
  97. BEGIN
  98.     NEW(e); e.handle := Handle; e.small := FALSE;
  99.     e.menu := TextFrames.Text(""); PopupElems.MeasureMenu(e);
  100.     insert.e := e; Viewers.Broadcast(insert)
  101. END Insert;
  102. BEGIN
  103.     SetDirName;
  104.     oldDirNotify := Directories.notify; Directories.notify := DirNotify
  105. END DirElems.
  106.